/* Susan(tm) Java Version
   by Thomas Lochmatter, Brig-Glis, Switzerland
   and Patrick Bizeau, Brig-Glis, Switzerland    */

package laWa;
import java.util.*;
import java.io.*;

// Routes SusanGame Events to more than one Listener
public class SusanGameMultiListener implements SusanGameListener {

  // ######################### INSTANCE VARIABLES
  
  // The eventhandlers to which to route the events
  HashSet eventhandler=null;

  // ######################### CONSTRUCTOR
  SusanGameMultiListener() {
    eventhandler = new HashSet();
  }

  // ######################### ADD/REMOVE LISTENERS
  
  // Adds a new listener
  public void add(SusanGameListener sgl) {
    if (sgl==null) {return;}
    eventhandler.add(sgl);
  }

  // removes a listener
  public void remove(SusanGameListener sgl) {
    eventhandler.remove(sgl);
  }

  // ######################### SUSANGAME EVENTS
  // All events are routed to the eventhandlers which have been registered
  // by the add method of this class.

  public void SusanGameLogEntry(String t) {
    Iterator i=eventhandler.iterator(); SusanGameListener sgl;
    while (i.hasNext()) {try {sgl=(SusanGameListener)(i.next());
      sgl.SusanGameLogEntry(t);
    } catch (Exception e) {}}
  }

  public void SusanGamePlacePerformed(int player, int to) {
    Iterator i=eventhandler.iterator(); SusanGameListener sgl;
    while (i.hasNext()) {try {sgl=(SusanGameListener)(i.next());
      sgl.SusanGamePlacePerformed(player,to);
    } catch (Exception e) {}}
  }

  public void SusanGameDragPerformed(int player, int from, int to) {
    Iterator i=eventhandler.iterator(); SusanGameListener sgl;
    while (i.hasNext()) {try {sgl=(SusanGameListener)(i.next());
      sgl.SusanGameDragPerformed(player,from,to);
    } catch (Exception e) {}}
  }

  public void SusanGamePrepareNextTurn(int player) {
    Iterator i=eventhandler.iterator(); SusanGameListener sgl;
    while (i.hasNext()) {try {sgl=(SusanGameListener)(i.next());
      sgl.SusanGamePrepareNextTurn(player);        
    } catch (Exception e) {}}
  }

  public void SusanGameFinished(int winner) {
    Iterator i=eventhandler.iterator(); SusanGameListener sgl;
    while (i.hasNext()) {try {sgl=(SusanGameListener)(i.next());
      sgl.SusanGameFinished(winner);
    } catch (Exception e) {}}
  }

  public void SusanGameComputerBegin() {
    Iterator i=eventhandler.iterator(); SusanGameListener sgl;
    while (i.hasNext()) {try {sgl=(SusanGameListener)(i.next());
      sgl.SusanGameComputerBegin();
    } catch (Exception e) {}}
  }
  
  public void SusanGameComputerEnd() {
    Iterator i=eventhandler.iterator(); SusanGameListener sgl;
    while (i.hasNext()) {try {sgl=(SusanGameListener)(i.next());
      sgl.SusanGameComputerEnd();
    } catch (Exception e) {}}
  }

  public void SusanGameComputerChangeStatus(String status) {
    Iterator i=eventhandler.iterator(); SusanGameListener sgl;
    while (i.hasNext()) {try {sgl=(SusanGameListener)(i.next());
      sgl.SusanGameComputerChangeStatus(status);
    } catch (Exception e) {}}
  }

  public void SusanGameHistoryChanged() {
    Iterator i=eventhandler.iterator(); SusanGameListener sgl;
    while (i.hasNext()) {try {sgl=(SusanGameListener)(i.next());
      sgl.SusanGameHistoryChanged();
    } catch (Exception e) {}}
  }

  public void SusanGameHistoryPositionChanged() {
    Iterator i=eventhandler.iterator(); SusanGameListener sgl;
    while (i.hasNext()) {try {sgl=(SusanGameListener)(i.next());
      sgl.SusanGameHistoryPositionChanged();
    } catch (Exception e) {}}
  }
}

// ######################### END OF FILE
